package com.people.netmon.reddit.monitor.service.impl;

import ai.people.core.standard.analysis.entity.request.JoinAnalysisRequest;
import ai.people.core.standard.analysis.service.AnalysisDataUserService;
import ai.people.netmon.framework.businessenum.AnalysisSourceEnum;
import ai.people.netmon.framework.businessenum.AnalysisTypeEnum;
import ai.people.netmon.framework.domain.reddit.entity.RedditAccount;
import ai.people.netmon.framework.domain.telegram.entity.AnalysisDataUser;
import com.people.netmon.reddit.monitor.service.AccountAnalysisService;
import com.people.netmon.reddit.probe.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 账户分析服务impl
 *
 * @author yuanqinglong
 * @date 2022/3/8 18:52
 */
@Service
public class AccountAnalysisServiceImpl implements AccountAnalysisService {


    @Autowired
    private AnalysisDataUserService analysisDataUserService;

    @Autowired
    private AccountService accountService;





    /**
     * 添加账户分析
     *
     * @param joinAnalysisRequest 加入分析请求
     */
    @Override
    public void addAccountAnalysis(JoinAnalysisRequest joinAnalysisRequest) {
        AnalysisDataUser analysisDataUser = new AnalysisDataUser(joinAnalysisRequest.getAnalysisTargetId(), joinAnalysisRequest.getAnalysisTargetName());
        analysisDataUser.setAnalysisType(AnalysisTypeEnum.ACCOUNT.getCode());
        analysisDataUser.setAnalysisSource(AnalysisSourceEnum.reddit.name());
        //analysisDataUser.setUserId(99387873L);
        RedditAccount redditAccount = accountService.getAccount(analysisDataUser.getAnalysisTargetName());
        analysisDataUser.setAvatarBackground(redditAccount.getBackgroundImage());
        analysisDataUser.setAvatarUrl(redditAccount.getHeaderImage());
        analysisDataUserService.addAnalysisData(analysisDataUser);
    }


    /**
     * 删除账户分析
     *
     * @param joinAnalysisRequest 加入分析请求
     */
    @Override
    public void deleteAccountAnalysis(JoinAnalysisRequest joinAnalysisRequest) {
        AnalysisDataUser analysisDataUser = new AnalysisDataUser(joinAnalysisRequest.getAnalysisTargetId(), joinAnalysisRequest.getAnalysisTargetName());
        //analysisDataUser.setUserId(99387873L);
        analysisDataUser.setAnalysisType(AnalysisTypeEnum.ACCOUNT.getCode());
        analysisDataUser.setAnalysisSource(AnalysisSourceEnum.reddit.name());
        analysisDataUserService.deleteAnalysisData(analysisDataUser);
    }
}
